package com.youhome.housing.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.service.ListHubService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * Created by chen365 on 2019/03/22.
 */
@RestController
@Api(tags = "房源", position = 2)
@RequestMapping(value = "/house")
public class HouseController {

    @Autowired
    private ListHubService listHubService;

    @ApiOperation(value = "房源列表", notes = "房源列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "")
    public Object list() {
        return new Result<>(ResultCode.SUCCESS);
    }

    @ApiOperation(value = "创建房源", notes = "创建房源", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping(value = "")
    public Object create() {
        return new Result<>(ResultCode.SUCCESS);
    }

    @ApiOperation(value = "修改房源", notes = "修改房源", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PutMapping(value = "")
    public Object update() {
        return new Result<>(ResultCode.SUCCESS);
    }

    @ApiOperation(value = "房源详情", notes = "房源详情", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "/{houseId}")
    public Object details(@PathVariable String houseId) {
        return new Result<>(ResultCode.SUCCESS);
    }

    @ApiOperation(value = "删除房源", notes = "删除房源", response = Result.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParam(dataType = "String", name = "houseId", value = "房源ID", required = true, paramType = "path")
    @DeleteMapping(value = "/{houseId}")
    public Object delete(@PathVariable("houseId") String houseId) throws CustomException {
        listHubService.delete(houseId);
        return new Result(ResultCode.SUCCESS);
    }
}
